/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tok.predmeta;

/**
 *
 * @author root
 */
import java.awt.AWTEventMulticaster;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
* A simple timer to wait for a given amount of time, fire an ActionEvent then quit
*
* @author D. Johnson
* @version 1.0
*/
public class TestTimer extends Thread {
    private int waitFor;
    private ActionListener actionListener = null;

    /**
     * Creates a new instance of TestTimer
     *
     * @param waitFor the time in milliseconds to run then fire an ActionEvent
     */
    public TestTimer(int waitFor) {
        this.waitFor = waitFor;
    }

    public void run() {
      try {
        sleep(waitFor);
        if (actionListener != null) {
            actionListener.actionPerformed(new ActionEvent(this, 0, "Times up"));
        }
        return;
      }
      catch (InterruptedException ie) {
          return;
      }
    }
   
  /**
   * Adds an ActionListener to this timer
   */
   public void addActionListener(ActionListener l) {
     actionListener = AWTEventMulticaster.add(actionListener, l);
   }

  /**
   * Removes an ActionListener from this timer.
   */
   public void removeActionListener(ActionListener l) {
     actionListener = AWTEventMulticaster.remove(actionListener, l);
   }
}
